import Vue from 'vue'
import VueRouter from 'vue-router'

// import Login from '../components/Login'
const Login = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Login')
// import Home from "../components/Home";
const Home = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Home')
// import Welcome from "../components/Welcome";
const Welcome  = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Welcome')

// import User from "../components/user/User";
const User  = () => import(/* webpackChunkName:"User_Rights_Roles" */ '../components/user/User')
// import Rights from "../components/power/Rights";
const Rights  = () => import(/* webpackChunkName:"User_Rights_Roles" */ '../components/power/Rights')
// import Roles from "../components/user/Roles";
const Roles  = () => import(/* webpackChunkName:"User_Rights_Roles" */ '../components/user/Roles')

// import Cate from "../components/goods/Cate";
const Cate  = () => import(/* webpackChunkName:"Cate_Params" */ '../components/goods/Cate')
// import Params from "../components/goods/Params";
const Params  = () => import(/* webpackChunkName:"Cate_Params" */ '../components/goods/Params')

// import List from "../components/goods/List";
const List  = () => import(/* webpackChunkName:"List_Add" */ '../components/goods/List')
// import Add from "../components/goods/Add";
const Add = () => import(/* webpackChunkName:"List_Add" */ '../components/goods/Add')

// import Order from "../components/order/Order";
const Order = () => import(/* webpackChunkName:"Order_Repoet" */ '../components/order/Order')
// import Repoet from "../components/report/Repoet";
const Repoet = () => import(/* webpackChunkName:"Order_Repoet" */ '../components/report/Repoet')


Vue.use(VueRouter)

  const routes = [
    {
      path:'',
      redirect:'/login'
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children:[
          {
            path:'/welcome',
            component:Welcome
          },
        {
          path: '/users',
          component: User
        },
        {
          path: '/rights',
          component: Rights
        },
        {
          path: '/roles',
          component: Roles
        },
        {
          path: '/categories',
          component: Cate
        },
        {
          path: '/params',
          component: Params
        },
        {
          path: '/goods',
          component: List
        },
        {
          path: '/goods/add',
          component: Add
        },
        {
          path: '/orders',
          component: Order
        },
        {
          path: '/reports',
          component: Repoet
        }
      ]
    },


]

const router = new VueRouter({
  routes
})

//挂载路由导航守卫
router.beforeEach((to,from,next) =>{
  //to 访问的路径
  if(to.path =='/login') return next();
  //获取token
  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login')
  next()
})

export default router
